home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / grafix / tools / amipeg_0.4 / video.h < prev    next >
C/C++ Source or Header  |  1994-04-22  |  10KB  |  243 lines

  1.  
  2. #include <stdio.h>
  3. #include <setjmp.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. typedef int INT32;
  8. typedef short INT16;
  9. typedef char INT8;
  10. typedef unsigned int UINT32;
  11. typedef unsigned short UINT16;
  12. typedef unsigned char UINT8;
  13.  
  14. /* Define Parsing error codes. */
  15.  
  16. #define SKIP_PICTURE -10
  17. #define SKIP_TO_START_CODE -1
  18. #define PARSE_OK 1
  19.  
  20. /* Define BOOLEAN, TRUE, and FALSE. */
  21.  
  22. #define BOOLEAN int
  23. #define TRUE 1
  24. #define FALSE 0
  25.  
  26. /* Set ring buffer size. */
  27.  
  28. #define RING_BUF_SIZE 5
  29.  
  30. /* Macros for picture code type. */
  31.  
  32. #define I_TYPE 1
  33. #define P_TYPE 2
  34. #define B_TYPE 3
  35.  
  36. /* Start codes. */
  37.  
  38. #define SEQ_END_CODE 0x000001b7
  39. #define SEQ_START_CODE 0x000001b3
  40. #define GOP_START_CODE 0x000001b8
  41. #define PICTURE_START_CODE 0x00000100
  42. #define SLICE_MIN_START_CODE 0x00000101
  43. #define SLICE_MAX_START_CODE 0x000001af
  44. #define EXT_START_CODE 0x000001b5
  45. #define USER_START_CODE 0x000001b2
  46.  
  47. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  48.  
  49. #define MB_QUANTUM 100
  50.  
  51. /* Macros used with macroblock address decoding. */
  52.  
  53. #define MB_STUFFING 34
  54. #define MB_ESCAPE 35
  55.  
  56. /* Lock flags for pict images. */
  57.  
  58. #define DISPLAY_LOCK 0x01
  59. #define PAST_LOCK 0x02
  60. #define FUTURE_LOCK 0x04
  61.  
  62. #define GRAY_DITHER 6
  63. #define FULL_COLOR_DITHER 7
  64. #define NO_DITHER 8
  65.  
  66. /* Temporary definition of time stamp structure. */
  67.  
  68. typedef int TimeStamp;
  69.  
  70. /* Structure with reconstructed pixel values. */
  71.  
  72. typedef struct pict_image {
  73.   unsigned char *luminance;              /* Luminance plane.   */
  74.   unsigned char *Cr;                     /* Cr plane.          */
  75.   unsigned char *Cb;                     /* Cb plane.          */
  76.   unsigned char *display;                /* Display plane.     */
  77.   int locked;                            /* Lock flag.         */
  78.   TimeStamp show_time;                   /* Presentation time. */
  79. } PictImage;
  80.  
  81. /* Group of pictures structure. */
  82.  
  83. typedef struct GoP {
  84.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  85.   unsigned int tc_hours;                 /* Hour component of time code.   */
  86.   unsigned int tc_minutes;               /* Minute component of time code. */
  87.   unsigned int tc_seconds;               /* Second component of time code. */
  88.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  89.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  90.                         previous group of pictures.    */
  91.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  92.   char *ext_data;                        /* Extension data.                */
  93.   char *user_data;                       /* User data.                     */
  94. } GoP;
  95.  
  96. /* Picture structure. */
  97.  
  98. typedef struct pict {
  99.   unsigned int temp_ref;                 /* Temporal reference.             */
  100.   unsigned int code_type;                /* Frame type: P, B, I             */
  101.   unsigned int vbv_delay;                /* Buffer delay.                   */
  102.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  103.                         pixel values flag.              */
  104.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  105.   unsigned int forw_f;                   /* Used for vector decoding.       */
  106.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  107.                         pixel values flag.              */
  108.   unsigned int back_r_size;              /* Used in decoding.               */
  109.   unsigned int back_f;                   /* Used in decoding.               */
  110.   char *extra_info;                      /* Extra bit picture info.         */
  111.   char *ext_data;                        /* Extension data.                 */
  112.   char *user_data;                       /* User data.                      */
  113. } Pict;
  114.  
  115. /* Slice structure. */
  116.  
  117. typedef struct slice {
  118.   unsigned int vert_pos;                 /* Vertical position of slice. */
  119.   unsigned int quant_scale;              /* Quantization scale.         */
  120.   char *extra_info;                      /* Extra bit slice info.       */
  121. } Slice;
  122.  
  123. /* Macroblock structure. */
  124.  
  125. typedef struct macroblock {
  126.   int mb_address;                        /* Macroblock address.              */
  127.   int past_mb_addr;                      /* Previous mblock address.         */
  128.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  129.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  130.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  131.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  132.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  133.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  134.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  135.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  136.   unsigned int cbp;                      /* Coded block pattern.             */
  137.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  138.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  139.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  140.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  141.   int recon_right_for_prev;              /* Past right forw. vector.         */
  142.   int recon_down_for_prev;               /* Past down forw. vector.          */
  143.   int recon_right_back_prev;             /* Past right back vector.          */
  144.   int recon_down_back_prev;              /* Past down back vector.           */
  145. } Macroblock;
  146.  
  147. /* Block structure. */
  148.  
  149. typedef struct block {
  150.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  151.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  152.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  153.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  154. } Block;
  155.  
  156. /* Video stream structure. */
  157.  
  158. typedef struct vid_stream {
  159.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  160.   unsigned int v_size;                         /* Vert. size in pixels.      */
  161.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  162.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  163.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  164.   unsigned char picture_rate;                  /* Code for picture rate.     */
  165.   unsigned int bit_rate;                       /* Bit rate.                  */
  166.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  167.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  168. #if 0
  169.   unsigned char intra_quant_matrix[8*8];       /* Quantization matrix for
  170.                           intracoded frames.         */
  171.   unsigned char non_intra_quant_matrix[8*8];   /* Quanitization matrix for 
  172.                           non intracoded frames.     */
  173. #endif
  174.   char *ext_data;                              /* Extension data.            */
  175.   char *user_data;                             /* User data.                 */
  176.   GoP group;                                   /* Current group of pict.     */
  177.   Pict picture;                                /* Current picture.           */
  178.   Slice slice;                                 /* Current slice.             */
  179.   Macroblock mblock;                           /* Current macroblock.        */
  180.   Block block;                                 /* Current block.             */
  181.   int state;                                   /* State of decoding.         */
  182.   int bit_offset;                              /* Bit offset in stream.      */
  183.   unsigned int *buffer;                        /* Pointer to next byte in
  184.                           buffer.                    */
  185.   int buf_length;                              /* Length of remaining buffer.*/
  186.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  187.   int max_buf_length;                          /* Max lenght of buffer.      */
  188.   PictImage *past;                             /* Past predictive frame.     */
  189.   PictImage *future;                           /* Future predictive frame.   */
  190.   PictImage *current;                          /* Current frame.             */
  191.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  192.  
  193.   unsigned short *intra_quant_matrix_ptr[32];        /* Quantization matrix for intracoded frames.
  194.                                The zero entry is for security reason only.     */
  195.  
  196.   BOOLEAN non_intra_default;                /* default non_intra matrix is all 16 */
  197.   unsigned short *non_intra_quant_matrix_ptr[32];    /* Quantization matrix for non intracoded frames.*/
  198.  
  199.   BOOLEAN display_is_initialized;        /* Resize display still to be done */
  200. } VidStream;   
  201.  
  202. /* Declaration of global pointer to current video stream. */
  203.  
  204. extern VidStream *curVidStream;
  205.  
  206. /* Quiet mode flag. */
  207. extern int quietFlag;
  208.  
  209. /* Definition of Contant integer scale factor. */
  210.  
  211. #define CONST_BITS 13
  212.  
  213. /* Misc DCT definitions */
  214. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  215. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  216.  
  217. typedef short DCTELEM;
  218. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  219.  
  220.  
  221. extern double realTimeStart;
  222. extern int totNumFrames;
  223. extern int loopFlag;
  224. extern int noDisplayFlag;
  225. extern jmp_buf env;
  226.  
  227. #ifdef ANALYSIS
  228. extern unsigned int bitCount;
  229. extern int showEachFlag;
  230. extern unsigned int cacheHit[8][8];
  231. extern unsigned int cacheMiss[8][8];
  232. #endif
  233.  
  234.  
  235. #define ExecuteDisplay(vid_stream)                                    \
  236. {                                                    \
  237.     totNumFrames++;                                            \
  238. /*    if (!quietFlag)                                            \
  239.         fprintf (stderr, "%d\r", totNumFrames);                            \
  240. */                                                    \
  241.     HAM8_draw((char *) vid_stream->current->display, vid_stream->h_size, vid_stream->v_size);    \
  242. }
  243.